//
// Description: 35. 搜索插入位置
// Created by Loading on 2025/4/8.
//

#include <bits/stdc++.h>

using namespace std;

int searchInsert(vector<int> &nums, int target) {
    int n = nums.size();
    int l = 0, r = n - 1;
    while (l <= r) {
        int mid = l + (r - l) / 2;
        // 找到第一个大于等于target的位置
        if (nums[mid] < target) {
            l = mid + 1;
        } else {
            r = mid - 1;
        }
    }

    return r + 1;
}

int main() {
    vector<int> nums{1, 3, 5, 6};
    int target = 5;

    auto res = searchInsert(nums, target);

    cout << res << endl;

    return 0;
}
